<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  
  <title>信奥题库（OI题库）8月月赛T1题解 幂次数 | Hexo</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="一道数学题">
<meta property="og:type" content="article">
<meta property="og:title" content="信奥题库（OI题库）8月月赛T1题解 幂次数">
<meta property="og:url" content="http://example.com/2020/08/29/%20%E4%BF%A1%E5%A5%A5%E9%A2%98%E5%BA%93%EF%BC%88OI%E9%A2%98%E5%BA%93%EF%BC%898%E6%9C%88%E6%9C%88%E8%B5%9BT1%E9%A2%98%E8%A7%A3%20%E5%B9%82%E6%AC%A1%E6%95%B0/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="一道数学题">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2020-08-29T10:09:09.190Z">
<meta property="article:modified_time" content="2023-07-19T11:50:00.969Z">
<meta property="article:author" content="John Doe">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/atom.xml" title="Hexo" type="application/atom+xml">
  
  
    <link rel="shortcut icon" href="/favicon.png">
  
  
    
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/typeface-source-code-pro@0.0.71/index.min.css">

  
  
<link rel="stylesheet" href="/css/style.css">

  
    
<link rel="stylesheet" href="/fancybox/jquery.fancybox.min.css">

  
  
<meta name="generator" content="Hexo 6.3.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">Hexo</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"><span class="fa fa-bars"></span></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
        
          <a class="nav-icon" href="/atom.xml" title="RSS Feed"><span class="fa fa-rss"></span></a>
        
        <a class="nav-icon nav-search-btn" title="Search"><span class="fa fa-search"></span></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://example.com"></form>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main"><article id="post- 信奥题库（OI题库）8月月赛T1题解 幂次数" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/2020/08/29/%20%E4%BF%A1%E5%A5%A5%E9%A2%98%E5%BA%93%EF%BC%88OI%E9%A2%98%E5%BA%93%EF%BC%898%E6%9C%88%E6%9C%88%E8%B5%9BT1%E9%A2%98%E8%A7%A3%20%E5%B9%82%E6%AC%A1%E6%95%B0/" class="article-date">
  <time class="dt-published" datetime="2020-08-29T10:09:09.190Z" itemprop="datePublished">2020-08-29</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="p-name article-title" itemprop="headline name">
      信奥题库（OI题库）8月月赛T1题解 幂次数
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <p>一道数学题</p>
<h1 id="0-前置知识"><a href="#0-前置知识" class="headerlink" title="0.前置知识"></a>0.前置知识</h1><ul>
<li><p>分解质因数</p>
</li>
<li><p>快速幂（不必要）</p>
</li>
</ul>
<h1 id="1-思路"><a href="#1-思路" class="headerlink" title="1.思路"></a>1.思路</h1><p>首先，我们知道一个正整数（设它为 $a$ ）一定能分解成这样的形式：</p>
<script type="math/tex; mode=display">a= \prod_{i\in N^*} p_i^{c_i}</script><p>其中， $p$ 为质数序列。</p>
<p><em>就是分解质因数。</em></p>
<blockquote>
<p>幂次数可以表示为 $a^b$（其中 $a$ 为质数， $b$ 为自然数）。如果 $a^b$ 整除正整数 $x$ ，并且 $a^{b+1}$ 不整除 $x$ ，那么我们称 $a^b$ 为正整数 $x$ 的幂次数。 ——摘自题目</p>
</blockquote>
<p>结合上面的“ $p<em>i^{c_i}$ ”，是不是发现了什么？没错， 幂次数一定等于 $p_i^{c_i}$ ！至于为什么，因为 $a$ 一定是一个质数（也就代表了不可能有因数），而且 $p_i^{c_i}$ 一定能整除 $x$ ，$p_i^{c</em>{i-1}}$ 、 $p<em>i^{c</em>{i-2}}$ 这些都存在 $a^{b+1}$ 能整除 $x$ ，所以，幂次数一定等于 $p_i^{c_i}$ 。</p>
<p>有了这个结论，思路就变得十分清晰了——先对 $x$ 分解质因数求出每个 $p_i$ 和 $c_i$ ，幂次数就一定是 $p_i^{c_i}$ 。 求出每个幂次数，再排序，输出前 $k$ 个幂次数。</p>
<h1 id="2-Code"><a href="#2-Code" class="headerlink" title="2.Code"></a>2.Code</h1><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;bits/stdc++.h&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"><span class="keyword">typedef</span> <span class="type">long</span> <span class="type">long</span> ll;</span><br><span class="line"><span class="function">map&lt;ll,ll&gt; <span class="title">get_prime_facs</span><span class="params">(ll x)</span></span>&#123; <span class="comment">//分解质因数，返回值代表每个ret[pi]=ci。</span></span><br><span class="line">    map&lt;ll,ll&gt; ret;</span><br><span class="line">    ll fuck=x;</span><br><span class="line">    <span class="keyword">for</span>(ll i=<span class="number">2</span>;i*i&lt;=x;i++)&#123;<span class="comment">//因为只可能存在一个大于根号x的因数，所以可以只循环到根号x</span></span><br><span class="line">        <span class="keyword">while</span>(fuck%i==<span class="number">0</span>)&#123;<span class="comment">//除掉每个i</span></span><br><span class="line">            fuck/=i;</span><br><span class="line">            ret[i]++;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span>(fuck!=<span class="number">1</span>)&#123;<span class="comment">//最后可能剩下一个大于根号x的因数</span></span><br><span class="line">        ret[fuck]++;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> ret;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function">ll <span class="title">quick_pow</span><span class="params">(ll x,ll y)</span></span>&#123;<span class="comment">//快速幂（其实不需要，换成暴力乘也可以）</span></span><br><span class="line">    <span class="keyword">if</span>(y==<span class="number">0</span>)&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="number">1</span>;</span><br><span class="line">    &#125;<span class="keyword">else</span> <span class="keyword">if</span>(y%<span class="number">2</span>==<span class="number">1</span>)&#123;</span><br><span class="line">        ll nxt=<span class="built_in">quick_pow</span>(x,y/<span class="number">2</span>);</span><br><span class="line">        <span class="keyword">return</span> nxt*nxt*x;</span><br><span class="line">    &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">        ll nxt=<span class="built_in">quick_pow</span>(x,y/<span class="number">2</span>);</span><br><span class="line">        <span class="keyword">return</span> nxt*nxt;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">ll x,k;</span><br><span class="line"><span class="function">ll <span class="title">cmp</span><span class="params">(<span class="type">const</span> ll &amp;l,<span class="type">const</span> ll &amp;r)</span></span>&#123;</span><br><span class="line">    <span class="keyword">return</span> l&gt;r;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span>&#123;</span><br><span class="line">    <span class="built_in">freopen</span>(<span class="string">&quot;num.in&quot;</span>,<span class="string">&quot;r&quot;</span>,stdin);</span><br><span class="line">    <span class="built_in">freopen</span>(<span class="string">&quot;num.out&quot;</span>,<span class="string">&quot;w&quot;</span>,stdout);</span><br><span class="line">    <span class="built_in">scanf</span>(<span class="string">&quot;%lld%lld&quot;</span>,&amp;x,&amp;k);</span><br><span class="line">    vector&lt;ll&gt; ans;</span><br><span class="line">    ans.<span class="built_in">push_back</span>(<span class="number">1</span>);</span><br><span class="line">    map&lt;ll,ll&gt; facs=<span class="built_in">get_prime_facs</span>(x);</span><br><span class="line">    <span class="keyword">for</span>(map&lt;ll,ll&gt;::iterator i=facs.<span class="built_in">begin</span>();i!=facs.<span class="built_in">end</span>();i++)&#123;</span><br><span class="line">        ans.<span class="built_in">push_back</span>(<span class="built_in">quick_pow</span>(i-&gt;first,i-&gt;second));</span><br><span class="line">    &#125;<span class="comment">//求出每个幂次数</span></span><br><span class="line">    <span class="built_in">sort</span>(ans.<span class="built_in">begin</span>(),ans.<span class="built_in">end</span>(),cmp);<span class="comment">//从大到小排序</span></span><br><span class="line">    <span class="keyword">for</span>(<span class="type">int</span> i=<span class="number">0</span>;i&lt;k;i++)&#123;<span class="comment">//输出最大的</span></span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;%lld &quot;</span>,ans[i]);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h6 id="3-点一个赞！"><a href="#3-点一个赞！" class="headerlink" title="3.点一个赞！"></a>3.点一个赞！</h6>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://example.com/2020/08/29/%20%E4%BF%A1%E5%A5%A5%E9%A2%98%E5%BA%93%EF%BC%88OI%E9%A2%98%E5%BA%93%EF%BC%898%E6%9C%88%E6%9C%88%E8%B5%9BT1%E9%A2%98%E8%A7%A3%20%E5%B9%82%E6%AC%A1%E6%95%B0/" data-id="clk9o8lmu00008wi50b62bqeu" data-title="信奥题库（OI题库）8月月赛T1题解 幂次数" class="article-share-link"><span class="fa fa-share">Share</span></a>
      
      
      
    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2021/06/06/KMP%E7%AE%97%E6%B3%95%E8%AF%A6%E8%A7%A3/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          KMP算法详解
        
      </div>
    </a>
  
  
    <a href="/2020/08/28/%E4%B8%A7%E5%BF%83%E7%97%85%E7%8B%82%E7%9A%84%E5%8E%8B%E8%A1%8C/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">丧心病狂的压行</div>
    </a>
  
</nav>

  
</article>


</section>
        
          <aside id="sidebar">
  
    

  
    

  
    
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2023/07/">July 2023</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2022/10/">October 2022</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2022/05/">May 2022</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2022/02/">February 2022</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2022/01/">January 2022</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/08/">August 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/07/">July 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/06/">June 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/08/">August 2020</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2023/07/17/%E5%86%B3%E7%AD%96%E5%8D%95%E8%B0%83%E6%80%A7%E4%BC%98%E5%8C%96DP%20%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0%20AND%20P4767%20%E3%80%8CIOI2000%E3%80%8D%20%E9%82%AE%E5%B1%80%20%E9%A2%98%E8%A7%A3/">决策单调性优化DP 学习笔记 AND P4767 「IOI2000」 邮局 题解</a>
          </li>
        
          <li>
            <a href="/2022/10/30/CSP-S%202022%20%E6%B8%B8%E8%AE%B0/">CSP-S 2022 游记</a>
          </li>
        
          <li>
            <a href="/2022/05/29/%E6%96%9C%E7%8E%87%E4%BC%98%E5%8C%96%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92%20%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/">斜率优化动态规划 学习笔记</a>
          </li>
        
          <li>
            <a href="/2022/05/22/PKUSC%E4%B8%80%E5%8F%A5%E8%AF%9D%E6%B8%B8%E8%AE%B0/">PKUSC一句话游记</a>
          </li>
        
          <li>
            <a href="/2022/05/18/%E7%9C%81%E9%80%89%E6%B8%B8%E8%AE%B0%EF%BC%9F%E7%9C%81%E9%80%89%E6%B8%B8%E5%AF%84%EF%BC%81/">省选游记？省选游寄！</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      
      &copy; 2023 John Doe<br>
      Powered by <a href="https://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>

    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    


<script src="/js/jquery-3.6.4.min.js"></script>



  
<script src="/fancybox/jquery.fancybox.min.js"></script>




<script src="/js/script.js"></script>





  </div>
</body>
</html>